package com.ruoyi.service.account.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.service.account.entity.LaborAccountEntity;
import com.ruoyi.service.account.mapper.LaborAccountMapper;
import com.ruoyi.service.account.service.LaborAccountService;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 员工账户 服务实现类
 * </p>
 *
 * @author Zane
 * @since 2025-10-19
 */
@Service
public class LaborAccountServiceImpl extends
    ServiceImpl<LaborAccountMapper, LaborAccountEntity> implements
    LaborAccountService {

  @Override
  public List<LaborAccountEntity> getListByLaborIds(List<Long> laborIds) {
    return list(queryWrapper().in(LaborAccountEntity::getLaborId, laborIds));
  }

  @Override
  public Map<Long, LaborAccountEntity> getMapByLaborIds(List<Long> laborIds) {
    return Optional.ofNullable(getListByLaborIds(laborIds)).orElseGet(ArrayList::new).stream()
        .collect(Collectors.toMap(LaborAccountEntity::getLaborId, v -> v, (v1, v2) -> v1));
  }

  @Override
  public LaborAccountEntity getByUserId(Long userId) {
    return getOne(queryWrapper().eq(LaborAccountEntity::getLaborId, userId));
  }

  private LambdaQueryWrapper<LaborAccountEntity> queryWrapper() {
    return new LambdaQueryWrapper<>();
  }
}
